import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:developer' as developer;

///
///  专门针对输入框 TextField 进行相关学习和了解
///  https://api.flutter-io.cn/flutter/material/TextField-class.html
///
///
///
///
class TextFieldPage extends StatefulWidget{


  @override
  State<TextFieldPage> createState()  => TextFieldPageSatate();
}


class TextFieldPageSatate extends State<TextFieldPage>{

  FocusNode passwordNode = FocusNode();

  // 文本控制器
  late TextEditingController  _controller ;


  String? text="";

  bool _isShowPassword = false;


  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = TextEditingController(text: "");
  }
  @override
  void dispose() {
    // TODO: implement dispose
    _controller.dispose();
    super.dispose();
  }




  @override
  Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text("输入框控件使用")
        ),
        body: ListView(
          children: [
            Text("输入框内容：${text ?? ""}"),
            TextField(
              //编辑框的控制器，通过它可以设置/获取编辑框的内容、选择编辑内容、监听编辑文本改变事件
              controller:_controller ,
              // 键盘类型
              keyboardType: TextInputType.text,
              //内容变化监听
              onChanged: (String? value){
                setState(() {
                  text = value;
                });
              },
              // 外观定制
              decoration: InputDecoration(
                labelText: "信息",
                hintText: "请输入信息",
                border: OutlineInputBorder(),
                prefixIcon: Icon(Icons.person)
              ),
            ),

            SizedBox(
              height: 30,
            ),

            Padding(padding: EdgeInsets.all(8.0),
            child:  TextField(
              obscureText: true,
              controller: _controller,
              decoration: InputDecoration(
                  hintText: "请输入密码",
                  prefixIcon: Icon(Icons.lock),
                  border: OutlineInputBorder()
              ),
            ),
            ),

            SizedBox(
              height: 30,
            ),

            Padding(padding: EdgeInsets.all(8.0),
              child:  TextField(
                obscureText: _isShowPassword,
                controller: _controller,
                focusNode: passwordNode,
                decoration: InputDecoration(
                    hintText: "请输入密码",
                    prefixIcon: Icon(Icons.lock),
                    border: OutlineInputBorder(),
                    suffixIcon: IconButton(
                    icon: Icon(
                        _isShowPassword?Icons.visibility :Icons.visibility_off
                    ), onPressed: (){
                        setState(() {
                          _isShowPassword = !_isShowPassword;
                        });
                      },
                    )
                ),
                textInputAction: TextInputAction.done,
                onSubmitted: (msg)=>{
                    ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text(msg)))
                },
              ),
            ),

            Padding(padding: EdgeInsets.all(8),
            child:    CupertinoTextField(
              obscureText: _isShowPassword,
              controller: _controller,
              placeholder: "请输入密码",
              focusNode: passwordNode,
              suffix:  IconButton(
                icon: Icon(
                    _isShowPassword?Icons.visibility :Icons.visibility_off
                ), onPressed: (){
                setState(() {
                  _isShowPassword = !_isShowPassword;
                });
              },
              ),
              padding: EdgeInsets.all(8.0),
              textInputAction: TextInputAction.done,
              onSubmitted: (msg)=>{
                ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text(msg)))
              },
            ),
            ),

          ],


        ),

      );
  }

}